package com.feng.controller;

import com.feng.annotation.SystemLog;
import com.feng.domain.ResponseResult;
import com.feng.domain.dto.RegisterUserDto;
import com.feng.domain.dto.UpdateUserDto;
import com.feng.domain.entity.User;
import com.feng.service.UserService;
import com.feng.utils.BeanCopyUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Api(tags = "用户")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "查询用户")
    @GetMapping("/userInfo")
    public ResponseResult userInfo(){
        return userService.userInfo();
    }

    @ApiOperation(value = "更新用户信息")
    @PutMapping("/userInfo")
    @SystemLog(businessName = "更新用户信息")
    public ResponseResult updateUserInfo(@RequestBody UpdateUserDto updateUserDto){
        User user = BeanCopyUtil.articleVo(updateUserDto, User.class);
        return userService.updateUserInfo(user);
    }

    @ApiOperation(value = "注册")
    @PostMapping("/register")
    public ResponseResult register(@RequestBody RegisterUserDto registerUserDto){
        User user = BeanCopyUtil.articleVo(registerUserDto, User.class);
        return userService.register(user);
    }
}
